package com.ayf.payment.game.api.service.impl;

import com.ayf.payment.game.api.dto.AybUserDTO;
import com.ayf.payment.game.api.entity.AybUser;
import com.ayf.payment.game.api.mapper.AybUserMapper;
import com.ayf.payment.game.api.service.AybUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AybUserServiceImpl implements AybUserService {

    @Resource
    private AybUserMapper aybUserMapper;

    @Override
    public AybUser getBindAybUser(Integer merchantId, Integer loginId) {
        AybUser wxUser = AybUser.builder().merchantId(merchantId).loginId(loginId).build();
        return aybUserMapper.selectOne(wxUser);
    }

    @Override
    public List<AybUser> getBindAybUser(Integer merchantId) {
        AybUser wxUser = AybUser.builder().merchantId(merchantId).build();
        return aybUserMapper.select(wxUser);
    }

    @Override
    public void updateAybMsgStatus(AybUserDTO aybUserDTO) {
        AybUser aybUser = AybUser.builder()
                .id(aybUserDTO.getId())
                .exceptionRemindStatus(aybUserDTO.getExceptionRemindStatus())
                .loginRemindStatus(aybUserDTO.getLoginRemindStatus())
                .rechargeRemindStatus(aybUserDTO.getRechargeRemindStatus())
                .build();
        aybUserMapper.updateByPrimaryKeySelective(aybUser);
    }

    @Override
    public AybUser getBindAybUserByAybId(Long aybId) {
        AybUser aybUser = AybUser.builder()
                .aybId(aybId)
                .build();
        return aybUserMapper.selectOne(aybUser);
    }

    @Override
    public void add(AybUserDTO aybUserDTO) {
        AybUser aybUser = AybUser.builder()
                .aybId(aybUserDTO.getAybId())
                .bindTime(aybUserDTO.getBindTime())
                .headImgUrl(aybUserDTO.getHeadImgUrl())
                .phone(aybUserDTO.getPhone())
                .nickname(aybUserDTO.getNickname())
                .loginId(aybUserDTO.getLoginId())
                .merchantId(aybUserDTO.getMerchantId())
                .type(aybUserDTO.getType())
                .exceptionRemindStatus(0)
                .loginRemindStatus(0)
                .rechargeRemindStatus(0)
                .build();
        aybUserMapper.insertSelective(aybUser);
    }

    @Override
    public void deleteById(Long id) {
        aybUserMapper.deleteByPrimaryKey(id);
    }
}
